package com.sh.动态规划;

import java.sql.Array;
import java.util.ArrayList;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 使用最小花费爬楼梯 {
    public static void main(String[] args) {
        int[] test = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        System.out.println(minCostClimbingStairs(test));
    }

    public static int minCostClimbingStairs(int[] cost) {
        int[] dp = new int[cost.length + 1];  // dp[i]    到达第i层楼梯的花费
        dp[0] = 0;
        dp[1] = 0;
        for (int i = 2; i <= cost.length; i++) {
            int i1 = dp[i - 1] + cost[i - 1];
            int i2 = dp[i - 2] + cost[i - 2];
            dp[i] = Math.min(i1, i2);
        }
        for (int i : dp) {
            System.out.print(i + "\t");
        }
        return  dp[cost.length];

    }
}

